home *** CD-ROM | disk | FTP | other *** search
- /*
-
- F W I N C O E R C I O N O S A X
-
- Version 1.0
- Freeware by Daniel Ranson
-
- This osax performs coercions to the FinderWindow (fwin) record
- type used by Finder events.
-
- There are actually three osax. This one converts a special type
- of list that can be used to refer to folder, get info or sharing
- windows. The format is :
- { kind, alias }
- Alias is an alias to the object the window is associated with.
- Kind is an integer indicating the kind of window. The possible
- values are :
- 0 : folder window
- 11 : get info window
- 13 : sharing window
-
- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <Aliases.h>
- #include <AppleEvents.h>
- #include <AERegistry.h>
-
- struct FinderWindow{
- long windowType;
- DescType aliasType;
- long aliasLength;
- AliasRecord alias;
- };
-
- typedef struct FinderWindow FinderWindow;
-
- /* This osax takes a descriptor in, while the other two take a buffer */
- pascal OSErr LIST2FWIN( AEDesc fromDesc,
- DescType toType,
- long refCon,
- AEDesc *result)
- {
- #pragma unused(toType, refCon)
-
- FinderWindow **hFwin;
- Size sizH;
- long val;
- AEKeyword aKey;
- DescType aType;
- Size aSize;
- OSErr err;
-
- /* Get kind */
- err = AEGetNthPtr(&fromDesc, 1, typeLongInteger, &aKey, &aType,
- &val, 4, &aSize);
- if ((err != noErr) || ((val != 0) && (val != 11) && (val != 13)))
- return errAECoercionFail;
-
- /* Get alias size */
- err = AESizeOfNthItem(&fromDesc, 2, &aType, &aSize);
- if (err != noErr) return errAECoercionFail;
-
- /* Allocate the structure */
- sizH = aSize + sizeof(FinderWindow) - sizeof(AliasRecord);
- hFwin = (FinderWindow**)NewHandle(sizH);
- if (hFwin == 0) return errAECoercionFail;
-
- /* Fill in fields */
- (**hFwin).windowType = val;
- (**hFwin).aliasType = typeAlias;
- (**hFwin).aliasLength = aSize;
-
- /* Create the descriptor */
- MoveHHi((Handle)hFwin);
- HLock((Handle)hFwin);
- err = AEGetNthPtr(&fromDesc, 2, typeAlias, &aKey, &aType,
- &((**hFwin).alias), aSize, &aSize);
- if (err != noErr){
- DisposeHandle((Handle)hFwin);
- return errAECoercionFail;
- }
- err = AECreateDesc(typeFinderWindow, (Ptr)(*hFwin), sizH, result);
-
- /* Clean up */
- DisposeHandle((Handle)hFwin);
- return err;
- }
-